<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="手机号"
        label="手机号"
        placeholder="手机号"
        :rules="rulesArr.ruleArr1"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="rulesArr.ruleArr2"
      />
      <van-field
        v-model="sms"
        center
        clearable
        label="短信验证码"
        placeholder="请输入短信验证码"
        name="短信验证码"
      >
        <template #button>
          <van-button size="small" type="primary">发送验证码</van-button>
        </template>
      </van-field>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      username: "",
      password: "",
      sms: "",
      rulesArr: {
        ruleArr1: [
          { required: true, message: "手机号不能为空" },
          {
            //pattern:
            //^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/,
            message: "请填写正确的手机号",
            validator: this.userHandle,
          },
        ],
        ruleArr2: [{ required: true, message: "请填写密码" }],
      },
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
    },
    userHandle(value) {
      let reg =
        /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
      let flag = reg.test(value);
      return flag;
    },
  },
};
</script>
<style lang='less'  scoped>
</style>
